home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / bin / httpd / Solaris_2 / AT-fetch.cgi < prev    next >
Text File  |  1997-02-25  |  4KB  |  150 lines

  1. #!/bin/sh
  2. perl=/tmp/httpd/.excite/perl
  3. eval "exec $perl -x $0 $*"
  4. #!perl
  5.  
  6. ##
  7. ## Copyright (c) 1996 Excite, Inc.
  8. ##
  9. ## This CGI script does one of four things depending on the
  10. ## command parameter.  If command is FETCH it finds and returns 
  11. ## the index file specified by the db and ext parameters. If
  12. ## the command is INFO then we return the modification dates
  13. ## and sizes of the index files specified by the db parameter.  
  14. ## If the command is LIST_ALL, it returns a list of the all of
  15. ## the collections at this server. If the command is LIST_PUB,
  16. ## it returns a list of the collections  at this server that 
  17. ## are subscribed to Bullseye notification. If the command is 
  18. ## EMAIL, it returns the e-mail address of the administrator 
  19. ## for that site.
  20. ## 
  21.  
  22.  
  23. BEGIN {
  24.   $root = "/tmp/httpd/.excite";
  25.   die "Invalid root directory '$root'\n" unless -d $root;
  26.   unshift(@INC, "$root/perllib");
  27. }
  28.  
  29. $| = 1;
  30.  
  31. require 'architext.pl';
  32. require 'architextConf.pl';
  33.  
  34. %form = &Architext'readFormArgs;
  35. %attr = &ArchitextConf'readConfig("$root/Architext.conf", $form{'db'});
  36.  
  37. if ($form{'command'} eq "FETCH") 
  38. {
  39.   $thepath = $attr{'CollectionIndex'}.'/'.$form{'db'}.'.'.$form{'ext'};
  40.   open(IDXFILE, "< $thepath") || die "Couldn't open index file $thepath";
  41.  
  42.   print "Content-Transfer-Encoding: binary\n";
  43.   print "Content-Type: application/octet-stream\n\n";
  44.  
  45.   while(<IDXFILE>) {
  46.     print;
  47.   }
  48.   close(IDXFILE);
  49. elsif ($form{'command'} eq "INFO") 
  50. {
  51.  
  52.   @ftypes = ('ptr', 'info', 'sum', 'url.map', 'sum.map', 'url.idx', 'sum.idx', 'key', 'dat');
  53.  
  54.   $head = $attr{'CollectionIndex'}.$form{'db'};
  55.  
  56.   print "Content-Type: text/plain\n\n";
  57.  
  58.   foreach $type (@ftypes) {
  59.     $thepath = $head . '.' . $type;
  60.     if (($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $modtime, $ctime, $blksize, $blocks) = stat("$thepath")) {
  61.       print "$type $size $modtime\n";
  62.     }
  63.   }
  64. }
  65.  
  66. elsif ($form{'command'} eq "LIST_ALL") 
  67. {
  68.   opendir(CONF, "$root/collections");
  69.   @dbconf = grep(/\.conf$/, readdir(CONF));
  70.   closedir CONF;
  71.  
  72.   print "Content-Type: text/plain\n\n";
  73.  
  74.   foreach $collection (@dbconf) {
  75.     $collection =~ s/\.conf$//;
  76.     print "$collection\n";
  77.   }
  78. }
  79.  
  80. elsif ($form{'command'} eq "LIST_PUB") 
  81. {
  82.   opendir(CONF, "$root/collections");
  83.   @pubconf = grep(/\.pub$/, readdir(CONF));
  84.   closedir CONF;
  85.  
  86.   print "Content-Type: text/plain\n\n";
  87.  
  88.   foreach $collection (@pubconf) {
  89.     $collection =~ s/\.pub$//;
  90.     print "$collection\n";
  91.   }
  92. }
  93.  
  94. elsif ($form{'command'} eq "EMAIL") 
  95. {
  96.   $eaddr = $attr{'AdminMail'};
  97.   print "Content-Type: text/plain\n\n";
  98.   print "$eaddr\n";
  99. }
  100.  
  101.  
  102. elsif ($form{'command'} eq "SPIDER") 
  103. {
  104.   ## returns BUILD if we need to build the url.idx url.map sum.idx and sum.map files
  105.   ## returns GOOD if they are already built and up to date
  106.   ## returns PROGRESS if they are being built at the moment
  107.  
  108.   $ans = "BUILD";
  109.   $head = $attr{'CollectionIndex'}.$form{'db'};
  110.   if (-e "$head.progress") {
  111.     ($dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $modtime) = stat("$head.progress");
  112.     if ($modtime > (time - 7200)) {
  113.       $ans = "PROGRESS";
  114.     }
  115.     else {
  116.       unlink "$head.progress";
  117.     }
  118.   }
  119.   if (($ans ne "PROGRESS") && (-e "$head.url.idx")
  120.                            && (-e "$head.url.map")
  121.                            && (-e "$head.sum.idx")
  122.                            && (-e "$head.sum.map")) {
  123.     ($dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $mod) = stat("$head.dat");
  124.     ($dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $t1) = stat("$head.url.idx");
  125.     ($dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $t2) = stat("$head.url.map");
  126.     ($dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $t3) = stat("$head.sum.idx");
  127.     ($dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $dm, $t4) = stat("$head.sum.map");
  128.     $ans = "GOOD" if (($t1 > $mod) && ($t2 > $mod) && ($t3 > $mod) && ($t4 > $mod));
  129.   }
  130.  
  131.   print "Content-Type: text/plain\n\n";
  132.   print "$ans\n";
  133.   print "spider-version-1\n";
  134. }
  135.  
  136. else
  137. {
  138.   die "Invalid command";
  139. }
  140.  
  141. ## HACK!!! this keeps the connection open long enough for us 
  142. ## to read the last bytes.
  143. sleep(1);
  144.  
  145. exit(0);
  146.  
  147.  
  148.  
  149.